package com.google.appengine.a4ieve;

import org.json.JSONArray;
import org.json.JSONObject;

public enum AchievementType {
    POSITIVE(1, "Positive"),
    NEGATIVE(0, "Negative");

    private static final JSONArray JSON_REPRESENTATION;

    static {
        JSONArray objects = new JSONArray();
        for (AchievementType a : values()) {
            JSONObject object = new JSONObject();
            object.put(Const.TYPE, a.isPositive);
            object.put(Const.NAME, a.screenName);
            objects.put(object);
        }
        JSON_REPRESENTATION = objects;
    }

    private int isPositive;
    private String screenName;

    public int getPositive() {
        return this.isPositive;
    }

    AchievementType(int id, String screenName) {
        this.isPositive = id;
        this.screenName = screenName;
    }

    public static AchievementType fromId(int id) {
        for (AchievementType v : values()) {
            if (v.isPositive == id) {
                return v;
            }
        }
        throw new IllegalArgumentException("You passed a wrong list option id");
    }

    //    public static String render() {
//        StringBuilder output = new StringBuilder("<span class=\"acheivement-title\">Choose achievement type: " +
//                "</span>&nbsp;<select id=\"type\">");
//        for (AchievementClass achievement : values()) {
//            output.append("<option value=\"").append(achievement.classId).append("\">")
//                    .append(achievement.screenName).append("</option>");
//        }
//        output.append("</select>");
//        return output.toString();
//    }
    public static JSONArray getRepresentation() {
        return JSON_REPRESENTATION;
    }
}
